package com.fulllife.food.controller;

import com.fulllife.food.entity.FoodEntity;
import com.fulllife.food.entity.MenuEntity;
import com.fulllife.food.entity.RecentEntity;
import com.fulllife.food.foodstrategy.Analyse;
import com.fulllife.food.foodstrategy.MeatStrategy;
import com.fulllife.food.foodstrategy.RangeMenu;
import com.fulllife.food.service.FoodService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
import org.hswebframework.web.crud.web.reactive.ReactiveCrudController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/recent")
@Tag(name = "最近所食")
public class RecentController implements ReactiveCrudController<RecentEntity, String> {

    @Resource
    private ReactiveRepository<RecentEntity, String> reactiveRepository;

    @Override
    public ReactiveRepository<RecentEntity, String> getRepository() {
        return reactiveRepository;
    }

    @Resource
    private FoodService foodService;

    /**
     * 分析，缺什么
     * @param strategy
     * @return
     */
    @PostMapping("/analyze")
    public Mono<Analyse> analyze(@RequestParam(defaultValue = "meatStrategy") String strategy) {
        return foodService.analyze(new MeatStrategy());
    }

    /**
     * 建议，吃什么
     * @param strategy
     * @return
     */
    @PostMapping("/suggestion")
    public Flux<FoodEntity> suggestion(@RequestParam(defaultValue = "meatStrategy") String strategy) {
        return foodService.suggestion(new MeatStrategy());
    }

    /**
     * 随缘：一个大荤，一个小荤，一个素菜
     * @return
     */
    @PostMapping("/range")
    public Flux<MenuEntity> range() {
        return foodService.range();
    }

    /**
     * 安排一下今天一整天的饭菜吧
     * @return
     */
    @PostMapping("/rangeDay")
    public Mono<RangeMenu> rangeDay() {
        return foodService.rangeDay();
    }

}
